﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerAnimation : MonoBehaviour
{
    private Animator anim;
    private PlayerControl movement;
    private Rigidbody2D rb;

    int groundID;
    int crouchID;
    int speedID;
    int hangID;
    int fallID;

    void Start()
    {
        anim = GetComponent<Animator>();
        movement = GetComponentInParent<PlayerControl>();
        rb= GetComponentInParent<Rigidbody2D>();

        groundID = Animator.StringToHash("isOnGround");
        crouchID = Animator.StringToHash("isCrouching");
        speedID = Animator.StringToHash("speed");
        hangID = Animator.StringToHash("isHanging");
        fallID = Animator.StringToHash("verticalVelocity");
    }

    void Update()
    {
        anim.SetFloat(speedID,Mathf.Abs(movement.xVelocity));
        anim.SetBool(crouchID,movement.isCrouch);
        anim.SetBool(groundID,movement.isOnGround);
        anim.SetBool(hangID,movement.isHanging);
        anim.SetFloat(fallID,rb.velocity.y);
    }

    void StepAudio() 
    {
        AudioManager.PlayFootstepAudio();
    }

    void CrouchStepAudio() 
    {
        AudioManager.PlayCrouchFootstepAudio();
    }
}
